using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SkillHeal : SkillBasic
{
    public float CD;
    private float CDtime;
    PlayerBasic player;
    ParticleSystem particle;
    public float skilltime;
    public float damagereduction;
    public float recoverry;
    public float Bigrecoverry;
    bool isskilling;
    // Start is called before the first frame update
    void Start()
    {
        player = GetComponentInParent<PlayerBasic>();
        particle = GetComponentInChildren<ParticleSystem>();
        particle.Stop();
        HealCD.CD = CD;
        HealCD.CDCurrent = 0;
        isskilling = false;
    }
    void skillend()
    {
        player.damagereduction = 0;
        particle.Stop();
        isskilling = false;
    }
    public IEnumerator Skilling()
    {
        yield return new WaitForSeconds(skilltime);
        skillend();

    }
    void Skill()
    {
        player.Recovery(Bigrecoverry * player.health);
        isskilling = true;
        player.damagereduction = damagereduction;
        particle.Play();
        StartCoroutine(Skilling());
    }
    void Update()
    {
        if (CDtime > 0)
        {
            CDtime -= Time.deltaTime;
            HealCD.CDCurrent = CDtime;
        }
        if (Input.GetKeyDown(KeyCode))
        {
            if (CDtime <= 0 && Time.timeScale > 0)
            {
                Skill();
                CDtime = CD;
            }
        }
        if (isskilling)
        {
            player.Recovery(recoverry * player.health);
        }
    }
}
